package com.example.mylibrarybase.yumengmeng08.utils.dialog;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.widget.TextView;

import com.example.mylibrarybase.R;
import com.example.mylibrarybase.utils.BasicNameValuePair.TextUtils;
import com.example.mylibrarybase.utils.LogUtils;


/**
 * Created by Administrator 于萌萌
 * 创建日期: 9:17 . 2016年06月24日
 * 描述: Dialog 方便的 工具类   懒死了  是不是一辈子 都不用写了
 * <p/>
 * <p/>
 * 备注:
 */
public class DialogUtils {
    //
    //dialog 显示的信息
    //电话寻购
    public   static final String PHONE_GENERATE_INQUIRY   = "电话询价提示";
    public  static final String PHONE_GENERATE_INQUIRY_HINT = "您是要通知买家按照电话所述生成订单并支付吗?";


    //取消订单
    public   static final String CANCEL_SETTITLE_ORDER_FORM  = "取消订单提示";
    public  static final String CANCEL_SETMESSAGE_ORDER_FORM = "是否取消订单?";
    //货站代收
    public   static final String FREIGHT_STATION  = "货站代收收货提示";
    public  static final String FREIGHT_STATION_TISHI = "是否确定货站代收收货? 货站代收所产生的一切纠纷就爱车概不负责";
    //确定付款
    public   static final String CONFIRM_PAYMENT_HINT  = "确认付款提示";
    public  static final String CONFIRM_PAYMENT = "是否确认付款?";
    //提醒发货
    public   static final String REMINDER_DELIVERY   = "提醒发货提示";
    public  static final String CONFIRM_THE_DELIVERY  = "是否确认提醒发货?";

    //删除订单
    public   static final String DELETE_ORDER_PROMPT   = "删除订单提示";
    public  static final String CONFIRM_DELETE_ORDER  = "是否确认删除订单?";
    //闪电收货
    public   static final String LIGHTNING_RECEIVING_TIPS   = "闪电收货提示";
    public  static final String SELECT_LIGHTNING_RECEIVING  = "是否确认闪电收货?";

    //延时收货
    public   static final String DELAY_PAYMENT   = "延时收货提示";
    public  static final String SELECT_DELAY_PAYMENT  = "是否确认延时收货?";

    //评价
    public   static final String ASSESS   = "评价提示";
    public  static final String SELECT_ASSESS  = "是否确认评价?";

    //确定 和取消
    public static final String CONFIRM = "确定";
    public static final String CANCEL = "取消";


    //返回状态
    public static final int CONFIRM_STATUSCODE = -1;
    public static final int CANCEL_STATUSCODE = -2;

    public static callback mCallback;

    public Context context;

    //你点了啥
    private static String selectorButton ="";

    /**
     * 通过 进来的按钮设置
     * @param context
     * @param status
     * @param buttonName
     * @param listener
     */
    public static void startDialog( Context context,int status , String buttonName,int position,callback listener){
        String setTitle= "";
        String setMessage= "";
        LogUtils.i("我现在点的是"+buttonName);
        switch (buttonName){
            //取消订单
            case CheckStatus.CANCELLATION_OF_ORDER:
                selectorButton=CheckStatus.CANCELLATION_OF_ORDER;
                setTitle = CANCEL_SETTITLE_ORDER_FORM;
                setMessage = CANCEL_SETMESSAGE_ORDER_FORM;
            break;
            //删除订单
            case CheckStatus.DELETE_ORDERS:
                selectorButton=CheckStatus.DELETE_ORDERS;
                setTitle = DELETE_ORDER_PROMPT;
                setMessage = CONFIRM_DELETE_ORDER;
            break;
            //延时收货
            case CheckStatus.DELAYED_RECEIPT:
                selectorButton=CheckStatus.DELAYED_RECEIPT;
                setTitle = DELAY_PAYMENT;
                setMessage = SELECT_DELAY_PAYMENT;
            break;
            //闪电收货
            case CheckStatus.LIGHTNING_RECEIVING:
                selectorButton=CheckStatus.LIGHTNING_RECEIVING;
                setTitle = LIGHTNING_RECEIVING_TIPS;
                setMessage = SELECT_LIGHTNING_RECEIVING;
            break;
            //提醒发货
            case CheckStatus.REMINDER_DELIVERY:
                selectorButton=CheckStatus.REMINDER_DELIVERY;
                setTitle = REMINDER_DELIVERY;
                setMessage = CONFIRM_THE_DELIVERY;
            break;
            //确认收货
            case CheckStatus.CONFIRM_RECEIPT:
                selectorButton=CheckStatus.CONFIRM_RECEIPT;
                setTitle = FREIGHT_STATION;
                setMessage = FREIGHT_STATION_TISHI;
            break;
            //收货
            case CheckStatus.FREIGHT_STATION_SHOUHUO:
                selectorButton=CheckStatus.FREIGHT_STATION_SHOUHUO;
                setTitle = FREIGHT_STATION;
                setMessage = FREIGHT_STATION_TISHI;
            break;
            //付款
            case CheckStatus.PAYMENT:
                selectorButton=CheckStatus.PAYMENT;
                setTitle = CONFIRM_PAYMENT_HINT;
                setMessage = CONFIRM_PAYMENT;
            break;
            //评价
            case CheckStatus.APPRAISE:
                selectorButton=CheckStatus.APPRAISE;
                setTitle = ASSESS;
                setMessage = SELECT_ASSESS;
            break;
        }

        setDialog(context,status,setTitle,setMessage,position,listener);
    }

    /**
     * 自定义 头和文字 还有按钮的 dialog
     * @param context 上下文
     * @param status 状态
     * @param position 号码
     * @param listener 回调
     */
    public static void showDialog( Context context,int status , String title, String message,int position,callback listener) {
        String setTitle= "";
        String setMessage= "";
        if (!TextUtils.isEmpty(title)){
            setTitle = title;
        }
        if (!TextUtils.isEmpty(message)){
            setMessage = message;
        }

        setDialog(context,status,setTitle,setMessage,position,listener);
    }

    private static void setDialog(final Context context, final int status, final String setTitle, String setMessage, final int position,  final callback listener){
        mCallback = listener;
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
       // CustomDialog.Builder builder = new CustomDialog.Builder(context);
       // builder.set
        TextView textView = new TextView(context);
        textView.setText(setTitle);
        textView.setTextColor(context.getResources().getColor(R.color.black));
        builder.setTitle(setTitle); //设置标题
        TextView textViewfu = new TextView(context);
        textViewfu.setText(setMessage);
        textViewfu.setTextColor(context.getResources().getColor(R.color.gray));
        String s = textViewfu.getText().toString();
        builder.setMessage(s); //设置内容
        builder.setPositiveButton(CONFIRM, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();

                //设置你的操作事项
                //点的确定
                listener.confirm(selectorButton,CONFIRM,status,position);
            }
        });
        builder.setCancelable(false);
        builder.setNegativeButton(CANCEL,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {

                        listener.cancel();
                        dialog.dismiss();
                    }
                });

        builder.create().show();
    }

//    @Override
//    public void onDismiss(DialogInterface dialogInterface) {
//        if (null!=mCallback)
//        mCallback.dismiss();
//    }

    /**
     * 回调   状态 按钮的 回调
     */
    public  interface callback{
         void confirm(String selectorButton, String which, int status, int position);
         void cancel();
        void dismiss();

    }


    public static Dialog showLoading(Context context,String msg){
        Dialog dialog = new Dialog(context, R.style.Mydialog);
        dialog.setContentView(R.layout.loading_layout_08);
        TextView msgView = (TextView) dialog.findViewById(R.id.tv_loading);
        msgView.setText(msg);
        dialog.show();
        return dialog;
    }

    public static Dialog showLoading(Context context,int msg){
        return  showLoading(context,context.getString(msg));
    }
}
